import type * as T from './type'
import http from '@/utils/http'

/**
 * 上传头像
 * @param data
 */
export function uploadAvatar(data: FormData) {
  return http.patch(`/system/user/profile/updateAvatar`, data)
}

/**
 * 修改用户基本信息
 */
export function updateUserBaseInfo(data: { nickname: string, gender: number }) {
  return http.patch(`/system/user/profile/updateBasicInfo`, data)
}

/**
 * 修改密码
 */
export function updateUserPassword(data: { oldPassword: string, newPassword: string }) {
  return http.patch(`/system/user/profile/updatePassword`, data)
}

/**
 * 修改手机号
 */
export function updateUserPhone(data: { phone: string, captcha: string, oldPassword: string }) {
  return http.patch(`/system/user/profile/updatePhone`, data)
}

/**
 * 修改邮箱
 */
export function updateUserEmail(data: { email: string, captcha: string, oldPassword: string }) {
  return http.patch(`/system/user/profile/updateEmail`, data)
}

/**
 * 获取绑定的三方账号
 */
export function listThirdparty() {
  return http.get<T.BindThirdpartyAccountRes[]>(`/system/user/profile/thirdparty/list`)
}

/**
 * 绑定三方账号
 * @param source
 * @param data
 */
export function bindThirdparty(source: string, data: any) {
  return http.post(`/system/user/profile/thirdparty/bind/${source}`, data)
}

/**
 * 解绑三方账号
 * @param source
 */
export function unbindThirdparty(source: string) {
  return http.del(`/system/user/profile/thirdparty/unbind/${source}`)
}
